package caiwei.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import caiwei.android.R;

/**
 * 主布局体的GridView适配器
 * 
 * @author caiwei
 * @date2012-3-2
 * @version 1.0
 */
public class AdapterAppGrid extends BaseAdapter
{
	private class Holder
	{
		ImageView ivIcon;
		TextView tvName;
	}

	private Integer[] mImageInteger = { R.drawable.app_grid_base,
			R.drawable.app_grid_baseui, R.drawable.app_grid_advui,
			R.drawable.app_grid_adv_, R.drawable.app_grid_exp,
			R.drawable.app_grid_pretty, };
	private String[] mImageString = new String[6];

	private Context mContext;

	public AdapterAppGrid(Context pContext)
	{
		mContext = pContext;
		mImageString = pContext.getResources().getStringArray(
				R.array.MainBodyItemText);
	}

	@Override
	public int getCount()
	{
		return mImageString.length;
	}

	@Override
	public Object getItem(int position)
	{
		return mImageString[position];
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		Holder _Holder;
		if (convertView == null)
		{
			LayoutInflater _LayoutInflater = LayoutInflater.from(mContext);
			convertView = _LayoutInflater
					.inflate(R.layout.main_body_item, null);
			_Holder = new Holder();
			_Holder.ivIcon = (ImageView) convertView.findViewById(R.id.ivIcon);
			_Holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
			convertView.setTag(_Holder);
		} else
		{
			_Holder = (Holder) convertView.getTag();
		}
		_Holder.ivIcon.setImageResource(mImageInteger[position]);
		LinearLayout.LayoutParams _LayoutParams = new LinearLayout.LayoutParams(
				50, 50);
		_Holder.ivIcon.setLayoutParams(_LayoutParams);
		_Holder.ivIcon.setScaleType(ImageView.ScaleType.FIT_XY);

		_Holder.tvName.setText(mImageString[position]);

		return convertView;
	}

}
